﻿<UserControl
    x:Class="MvvmFx.Samples.HowTos.ViewModelHelper.Views.MasterDetailsSampleView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="clr-namespace:MvvmFx.Common.Converters;assembly=MvvmFx.Common"
    xmlns:mvvm="clr-namespace:MvvmFx.Common.ViewModels;assembly=MvvmFx.Common">

    <UserControl.Resources>

        <!-- converters -->
        <converters:ColorToSolidColorBrushConverter
            x:Key="converters.colorToSolidColorBrush" />

        <!-- data templates -->
        <mvvm:DataTemplate
            x:Key="viewModels.SampleItem"
            Type="MvvmFx.Samples.HowTos.ViewModelHelper.ViewModels.SampleItemViewModel">

            <Border
                Background="{Binding Path=Color, 
                    Converter={StaticResource converters.colorToSolidColorBrush}}">
                <Grid
                    Margin="5">

                    <!-- row/column definitions -->
                    <Grid.RowDefinitions>
                        <RowDefinition
                            Height="Auto" />
                        <RowDefinition
                            Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition
                            Width="Auto" />
                        <ColumnDefinition
                            Width="*" />
                    </Grid.ColumnDefinitions>

                    <!-- name -->
                    <TextBlock
                        Text="Name:"
                        Foreground="White"
                        FontFamily="Verdana"
                        FontSize="10"
                        FontWeight="Bold"
                        HorizontalAlignment="Right"
                        Margin="0, 0, 3, 0"
                        Grid.Row="0"
                        Grid.Column="0" />
                    <TextBlock
                        Text="{Binding Path=Name}"
                        Foreground="White"
                        FontFamily="Verdana"
                        FontSize="10"
                        Grid.Row="0"
                        Grid.Column="1" />

                    <!-- age -->
                    <TextBlock
                        Text="Age:"
                        Foreground="White"
                        FontFamily="Verdana"
                        FontSize="10"
                        FontWeight="Bold"
                        HorizontalAlignment="Right"
                        Margin="0, 0, 3, 0"
                        Grid.Row="1"
                        Grid.Column="0" />
                    <TextBlock
                        Text="{Binding Path=Age}"
                        Foreground="White"
                        FontFamily="Verdana"
                        FontSize="10"
                        Grid.Row="1"
                        Grid.Column="1" />
                </Grid>
            </Border>
        </mvvm:DataTemplate>

    </UserControl.Resources>

    <!-- root container -->
    <Grid
        Margin="10">

        <!-- row/column definitions -->
        <Grid.RowDefinitions>
            <RowDefinition
                Height="Auto" />
            <RowDefinition
                Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition
                Width="Auto" />
            <ColumnDefinition
                Width="*" />
        </Grid.ColumnDefinitions>

        <!-- items -->
        <TextBlock
            Text="Sample Data:"
            FontWeight="Bold"
            TextDecorations="Underline"
            Margin="10, 0, 0, 8" />
        <ScrollViewer
            Margin="0, 0, 20, 0"
            Grid.Row="1">
            <ListBox
                mvvm:ViewModelHelper.ItemsSource="{Binding Path=Samples}"
                mvvm:ViewModelHelper.SelectedValue="{Binding Path=SelectedSample,
                Mode=TwoWay}">
                <ListBox.Template>
                    <ControlTemplate
                        TargetType="ListBox">
                        <ItemsPresenter />
                    </ControlTemplate>
                </ListBox.Template>
            </ListBox>
        </ScrollViewer>

        <!-- selected item details -->
        <TextBlock
            Text="Item Details:"
            FontWeight="Bold"
            TextDecorations="Underline"
            Margin="0, 0, 0, 8"
            Grid.Column="1" />
        <ContentControl
            mvvm:ViewModelHelper.Content="{Binding Path=SelectedSample}"
            Grid.Row="1"
            Grid.Column="1">
            <ContentControl.Resources>
                
                <!-- data templates -->
                <mvvm:DataTemplate
                    x:Key="does.not.have.to.match.anything"
                    Type="MvvmFx.Samples.HowTos.ViewModelHelper.ViewModels.SampleItemViewModel">

                    <Grid
                        Margin="5">

                        <!-- name -->
                        <TextBlock
                            Text="{Binding Path=Name}"
                            Foreground="{Binding Path=Color, 
                                Converter={StaticResource converters.colorToSolidColorBrush}}"
                            FontSize="{Binding Path=Age}"
                            Grid.Row="0"
                            Grid.Column="1" />
                    </Grid>
                </mvvm:DataTemplate>
            </ContentControl.Resources>
        </ContentControl>

    </Grid>

</UserControl>
